package com.gitee.zycra.future.job.web.controller;

import com.gitee.zycra.future.job.common.bo.CommonResult;
import com.gitee.zycra.future.job.common.vo.JobNodeVO;
import com.gitee.zycra.future.job.service.JobNodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zycra
 */
@Slf4j
@RestController
@RequestMapping("/node")
public class JobNodeController {

    @Autowired
    private JobNodeService jobNodeService;

    /**
     * 获取节点信息
     *
     * @param applicationName 应用名称
     * @param nodeIp          节点IP
     * @return 节点信息
     */
    @GetMapping("/nodeInfo")
    public CommonResult<List<JobNodeVO>> nodeInfo(@RequestParam("applicationName") String applicationName,
                                                  @RequestParam(value = "nodeIp", required = false) String nodeIp) {
        List<JobNodeVO> jobNodeList = jobNodeService.selectByApplicationAndIp(applicationName, nodeIp);
        return CommonResult.success(jobNodeList);
    }
}
